using Gateway.Common.Entity;
using Gateway.Common.Enums;

namespace Gateway.Domain.Entities;

/// <summary>
/// 菜单/权限
/// </summary>
public class Menu : AggregateRootEntityBase
{
    /// <summary>
    /// 菜单code名称
    /// </summary>
    public string Name { get;private set; }

    /// <summary>
    /// 路由
    /// </summary>
    public string Path { get;private set; }

    /// <summary>
    /// 标题
    /// </summary>
    public string Title { get;private set; }

    /// <summary>
    /// icon
    /// </summary>
    public string Icon { get;private set; }

    /// <summary>
    /// 类型
    /// </summary>
    public MenuTypeEnum Type { get;private set; }

    /// <summary>
    /// 组件
    /// </summary>
    public string Component { get;private set; }

    /// <summary>
    /// 标记
    /// </summary>
    public string Tag { get;private set; }

    /// <summary>
    /// 隐藏菜单
    /// </summary>
    public BooleanStatusEnum Hidden { get;private set; }

    /// <summary>
    /// 隐藏面包屑
    /// </summary>
    public BooleanStatusEnum HiddenBreadcrumb { get;private set; }

    /// <summary>
    /// 固定
    /// </summary>
    public BooleanStatusEnum Affix { get;private set; }

    /// <summary>
    /// 父级标识
    /// </summary>
    public string ParentId { get;private set; }

    /// <summary>
    /// 颜色
    /// </summary>
    public string Color { get;private set; }

    /// <summary>
    /// 整页路由
    /// </summary>
    public BooleanStatusEnum FullPage { get;private set; }

    /// <summary>
    /// 高亮  子节点或详情页需要高亮的上级菜单路由地址
    /// </summary>
    public string Active { get;private set; }

    /// <summary>
    /// 排序序号
    /// </summary>
    public int SeqNo { get;private set; }

    /// <summary>
    /// 重定向
    /// </summary>
    public string Redirect { get;private set; }


    /// <summary>
    /// 接口权限集合
    /// </summary>
    public List<MenuApiAuth> ApiAuths { get;private set; }

    /// <summary>
    /// 层级编码
    /// </summary>
    public string LevelCode { get; set; }


    public Menu()
    {
        Hidden = BooleanStatusEnum.No;
        Affix = BooleanStatusEnum.No;
    }

    public Menu(string name = default, string path = default, string title = default, string icon = default,
        MenuTypeEnum type = default, string component = default, string tag = default,
        string hidden = default, string affix = default, string parentId = default, int seqNo = 0,
        string active = default,
        string color = default,
        string fullPage = default,
        string redirect = default,
        string hiddenBreadcrumb = default,
        string levelCode=default
    )
    {
        Name = name;
        Path = path;
        Title = title;
        Icon = icon;
        Type = type;
        Component = component;
        Tag = tag;
        Hidden = string.IsNullOrEmpty(hidden) ? BooleanStatusEnum.No : BooleanStatusEnum.FromValue(hidden);
        Affix = string.IsNullOrEmpty(affix) ? BooleanStatusEnum.No : BooleanStatusEnum.FromValue(affix);
        FullPage = string.IsNullOrEmpty(fullPage) ? BooleanStatusEnum.No : BooleanStatusEnum.FromValue(fullPage);
        HiddenBreadcrumb = string.IsNullOrEmpty(hiddenBreadcrumb)
            ? BooleanStatusEnum.No
            : BooleanStatusEnum.FromValue(hiddenBreadcrumb);
        ParentId = parentId;
        Active = active;
        Redirect = redirect;
        Color = color;
        SeqNo = seqNo;
        this.LevelCode = levelCode;
    }

    public void Update(string name = default, string path = default, string title = default, string icon = default,
        MenuTypeEnum type = default, string component = default, string tag = default,
        string hidden = default, string affix = default, string parentId = default, int seqNo = 0,
        string active = default,
        string color = default,
        string fullPage = default,
        string redirect = default,
        string hiddenBreadcrumb = default, string levelCode=default)
    {
        Name = name;
        Path = path;
        Title = title;
        Icon = icon;
        Type = type;
        Component = component;
        Tag = tag;
        Hidden = string.IsNullOrEmpty(hidden) ? BooleanStatusEnum.No : BooleanStatusEnum.FromValue(hidden);
        Affix = string.IsNullOrEmpty(affix) ? BooleanStatusEnum.No : BooleanStatusEnum.FromValue(affix);
        SeqNo = seqNo;
        FullPage = string.IsNullOrEmpty(fullPage) ? BooleanStatusEnum.No : BooleanStatusEnum.FromValue(fullPage);
        HiddenBreadcrumb = string.IsNullOrEmpty(hiddenBreadcrumb)
            ? BooleanStatusEnum.No
            : BooleanStatusEnum.FromValue(hiddenBreadcrumb);
        ParentId = parentId;
        Active = active;
        Redirect = redirect;
        Color = color;
        if (!string.IsNullOrEmpty(levelCode))
            this.LevelCode = levelCode;
    }


    public void SetApiAuths(List<MenuApiAuth> list)
    {
        ApiAuths = list;
    }

    /// <summary>
    /// 设置父级标识
    /// </summary>
    /// <param name="parentId">父级标识</param>
    public void SetParentId(string parentId)
    {
        this.ParentId = parentId;
    }
}